unit KnjigaDolgovRpt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBBaseRpt, DokumentRpt, DB, DBClient, alBaseDataSet, MConnect,
  EXLReportExcelTLB, EXLReportBand, EXLReport;

type
  TrptKnjigaDolgov = class(TrptDokument)
  private
    { Private declarations }
  protected
    function GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations; override;
    procedure Initialize; override;
    procedure OnCalcExpression(Sender: TEXLReportBand; var GroupValue: String);
    procedure OnGetFieldValue(Sender: TObject; const Field: String;
      var Value: OleVariant);
  public
    { Public declarations }
  end;

var
  rptKnjigaDolgov: TrptKnjigaDolgov;

implementation

{$R *.dfm}

{ TrptKnjigaDolgov }

function TrptKnjigaDolgov.GetSessionParamRelations(
  DataSet: TDataSet): TSessionParamRelations;
begin
  if DataSet = cdsMain then
  begin
    SetLength(Result, 1);
    Result[0].FieldName := 'REF_ID';
    Result[0].SessionName := 'POSLOVNO_LETO_ID';
  end;
end;

procedure TrptKnjigaDolgov.Initialize;
var
  TitleBand: TExlReportBand;
  GroupHeaderBand: TExlReportGroupHeaderBand;
  MasterDataBand: TExlReportBand;
  GroupFooterBand: TExlReportGroupFooterBand;
  SummaryBand: TExlReportBand;
begin
  inherited;
  rptMain.OnGetFieldValue := OnGetFieldValue;
  TitleBand := rptMain.Bands.AddBand(xlrbtTitle);
  TitleBand.Range := 'A1:G4';
  GroupHeaderBand := TExlReportGroupHeaderBand(rptMain.Bands.AddBand(xlrbtGroupHeader));
  GroupHeaderBand.Range := 'A5:G6';
  GroupHeaderBand.OnCalcExpression := OnCalcExpression;
  MasterDataBand := rptMain.Bands.AddBand(xlrbtMasterData);
  MasterDataBand.Range := 'A7:G8';
  GroupFooterBand := TExlReportGroupFooterBand(rptMain.Bands.AddBand(xlrbtGroupFooter));
  GroupFooterBand.Range := 'A9:G9';
  SummaryBand := rptMain.Bands.AddBand(xlrbtSummary);
  SummaryBand.Range := 'A10:G11';
  GroupHeaderBand.Footer := GroupFooterBand;
end;

procedure TrptKnjigaDolgov.OnCalcExpression(Sender: TEXLReportBand;
  var GroupValue: String);
begin
  GroupValue := cdsMain.FieldByName('POSLOVNI_PARTNER_NAZIV').AsString;
end;

procedure TrptKnjigaDolgov.OnGetFieldValue(Sender: TObject;
  const Field: String; var Value: OleVariant);
begin
  if AnsiCompareText(Field, 'ZAPOREDNA_STEVILKA') = 0 then
    Value := cdsMain.RecNo;
end;

initialization
  RegisterClass(TrptKnjigaDolgov);

end.
